function serializeForm(form) {
    var parts = [];
    for (var i = 0, i1 = form.elements.length; i < i1; i++) {
        var field = form.elements[i];
        switch (field.type) {
            case 'select-one':
            case 'select-multiple':
                if (field.type.length) {
                    for (var j = 0, j1 = field.options.length; j < j1; j++) {
                        var option = field.options[j];
                        if (option.selected) {
                            var optionValue = '';
                            if (option.hasAttribute('value') && option.attributes['value'].specified) {
                                //specified表明是否有此属性，有的话返回true，若定义了此属性但尚未添加到元素中也返回true。
                                optionValue = option.text;
                            } else {
                                optionValue = optionValue.text;
                            }
                            parts.push(encodeURIComponent(field.name) + '=' + encodeURIComponent(optionValue));
                        }
                    }
                }
                break;
            case undefined:
            case 'file':
            case 'submit':
            case 'reset':
            case 'button':
                break;
            case 'radio':
            case 'checkbox':
                if (!field.checked) {
                    break;
                } else {
                    parts.push(encodeURIComponent(field.name) + '=' + encodeURIComponent(field.value));
                    break;
                }
            default:
                if (field.name.length) {
                    parts.push(encodeURIComponent(field.name) + '=' + encodeURIComponent(field.value));
                }
        }
    }
    return parts.join('&');
}